package com.sztx.pay.center.tool;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import org.apache.commons.io.FileUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sztx.commons.util.excel.ExcelUtil;
import com.sztx.commons.util.excel.ExcelUtil.ExcelType;
import com.sztx.pay.center.tool.bean.TxOrder;

public class CompareTransferOrder {
	private static Logger logger = LoggerFactory.getLogger(CompareTransferOrder.class);

	public static void main(String[] args) throws IOException {
		List<String> tfList = FileUtils.readLines(new File("E:\\work\\Berbon\\20160911上线\\通行迁移交易记录20160902-20160913.txt"));
		
		Map<String, String> tfOrder = new HashMap<String, String>();
		Set<String> txOrder = new HashSet<String>();
		
		for (String string : tfList) {
			if (string == null || string.trim().isEmpty()) {
				continue;
			}
			
			String[] orderInfo = string.split(",");
			if (orderInfo == null || orderInfo.length != 5) {
				logger.error("订单信息有误：{}",string);
				continue;
			}
			tfOrder.put(orderInfo[0], orderInfo[1]);
		}
		
		Collection<TxOrder> dataset = new ArrayList<TxOrder>();
		String[] headers = new String[]{"用户账号","订单金额","订单时间","通行订单号","通付订单号"};
		
		
		List<String> tzList = FileUtils.readLines(new File("E:\\work\\Berbon\\20160911上线\\201610091539.txt"));
		for (String string : tzList) {
			
			if (string == null || string.trim().isEmpty()) {
				continue;
			}
			
			String[] orderInfo = string.split("	");
			if (orderInfo == null || orderInfo.length != 5) {
				logger.error("订单信息有误：{}",string);
				continue;
			}
			
			txOrder.add(orderInfo[3]);
			
			String tfOrderNo = orderInfo[4]; 
			
			if (tfOrderNo.length() < 4) {
				tfOrderNo = tfOrder.get(orderInfo[3]);
				logger.error("{},{}", orderInfo[3], tfOrderNo);				
			}
			
			tfOrder.remove(orderInfo[3]);
			if (tfOrderNo != null) {
				txOrder.remove(orderInfo[3]);
				dataset.add(new TxOrder(orderInfo[0], Long.parseLong(orderInfo[1]), orderInfo[2], orderInfo[3], tfOrderNo));				
			}
		}
		
		ExcelUtil.exportExcel(headers , dataset, new FileOutputStream(new File("通行迁移用户订单0902-1008.xlsx")), null, ExcelType.XSSF);
		System.out.println("比对完毕");
		logger.error("通付多余订单：{}",tfOrder.keySet());
		logger.error("通行多余订单：{}",txOrder.size());
		
	}

}
